/**
    Copyright (c) 2010 yakiimo02
    Distributed under the New BSD License.
    See included license.txt or http://www.yakiimo3d.com/NewBSDLicense.txt
**/

#pragma once

#include "StructuredBufferTypes.h"

#include <vector>

/**    
    @brief  Random number buffer for Buddhabrot compute shader random sampling.
            Initially was using 2 buffers to ping-pong update a multiply with carry RNG in the compute
            shader (a different RNG in each cs thread), but noticed patterns in my RNG with this probably mathematically 
            unsound approach. 
            Now I just do RNG calc on the cpu and lock&transfer the values to a GPU texture. I probably should double or triple buffer to get rid of the CPU locking.
            I also should probably use a better RNG like the Mersenne twister.
    @author yakiimo02
    @date    2010/02/14
*/
class RandomNumBuffer
{
public:
    RandomNumBuffer();
    ~RandomNumBuffer();

    HRESULT OnResizedSwapChain( ID3D11Device* pd3dDevice, int nWidth, int nHeight, float fMinRe, float fMaxRe, float fMinIm, float fMaxIm );
    void    OnDestroyDevice();

    void    UpdateBuffer( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, float fMinRe, float fMaxRe, float fMinIm, float fMaxIm );

    inline ID3D11ShaderResourceView*        GetpSRV() { return m_pSRV; }

protected:
    ID3D11Texture2D*                m_pTexture;
    ID3D11ShaderResourceView*       m_pSRV;

    std::vector< D3DXVECTOR2 >        m_data;

    int                                m_nWidth;
    int                                m_nHeight;
};
